﻿using Landpy.CruiseControlNet.ConfigurationSidekick.ConfigTreeModule;
using Landpy.CruiseControlNet.ConfigurationSidekick.ParserModule;

namespace Landpy.CruiseControlNet.ConfigurationSidekick.ConfigPropertyModule
{
    class TaskHandler : GetPropertiesHandler
    {
        public override object GetPropertiesObject(GetPropertiesContext getPropertiesContext)
        {
            var treeNodeIndentity = this.GetTreeNodeIndentity(getPropertiesContext);
            if ((treeNodeIndentity.Type & TreeNodeType.Task) != TreeNodeType.Unknow)
            {
                ProjectChildCollectionKey taskKey = ProjectChildCollectionKeyUtil.GetKey(treeNodeIndentity.Key);
                var queryProject = this.ProjectRepository.GetProjectById(getPropertiesContext.CruiseControl,
                                                                         taskKey.ProjectId);
                if (queryProject != null)
                {
                    return this.TaskRepository.GetTaskById(queryProject, taskKey.Id);
                }
            }
            return this.Successor.GetPropertiesObject(getPropertiesContext);
        }
    }
}
